<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改轮播图')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-banner-edit" th:object="${banner}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">图片名称：</label>
                <div class="col-sm-8">
                    <input name="name" th:field="*{name}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">描述：</label>
                <div class="col-sm-8">
                    <input name="notes" th:field="*{notes}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">排序：</label>
                <div class="col-sm-8">
                    <input name="sort" th:field="*{sort}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">图片(690*388)：</label>
                <div class="col-sm-8">
                    <button type="button" class="layui-btn" id="test1">上传图片</button>
                    <div class="layui-upload-list">
                        <div id="img_header" style="padding: 5px;"><img th:src="*{headUrl}" style='height: 60px;width: 60px'></div>
                        <input type="hidden" id="headUrl" name="headUrl" th:field="*{headUrl}">
                        <p id="demoText1"></p>
                    </div>
                </div>
            </div>


            <div class="form-group">    
                <label class="col-sm-3 control-label">轮播状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('banner_status')}">
                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:field="*{status}">
                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">轮播类型：</label>
                <div class="col-sm-8">
                    <select name="type" id="type" class="form-control m-b" th:with="type=${@dict.getType('banner_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{type}"></option>
                    </select>
                </div>
            </div>
            <div id="banner_car"  th:style="'display:'+ @{(*{type}!=0? 'none':'block')}" >
                <div class="form-group">
                    <label class="col-sm-3 control-label">车辆选择：</label>
                    <div class="col-sm-8">
                        <!--<input name="jumpIdGoods" class="form-control" type="text">-->
                        <select name="resId" class="form-control m-b"  >
                            <option value="">请选择</option>
                            <option th:each="dict : ${carList}"
                                    th:text="${dict.name}"
                                    th:field="*{resId}"
                                    th:value="${dict.id}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div id="banner_activity"  th:style="'display:'+ @{(*{type}!=2? 'none':'block')}" >
                <div class="form-group">
                    <label class="col-sm-3 control-label">活动选择：</label>
                    <div class="col-sm-8">
                        <!--<input name="jumpIdGoods" class="form-control" type="text">-->
                        <select name="resId" class="form-control m-b"  >
                            <option value="">请选择</option>
                            <option th:each="dict : ${activityList}"
                                    th:text="${dict.name}"
                                    th:field="*{resId}"
                                    th:value="${dict.id}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div id="banner_goods"  th:style="'display:'+ @{(*{type}!=3? 'none':'block')}" >
                <div class="form-group">
                    <label class="col-sm-3 control-label">商品选择：</label>
                    <div class="col-sm-8">
                        <!--<input name="jumpIdGoods" class="form-control" type="text">-->
                        <select name="resId" class="form-control m-b"  >
                            <option value="">请选择</option>
                            <option th:each="dict : ${goodsList}"
                                    th:text="${dict.name}"
                                    th:field="*{resId}"
                                    th:value="${dict.id}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div id="banner_used"  th:style="'display:'+ @{(*{type}!=4? 'none':'block')}" >
                <div class="form-group">
                    <label class="col-sm-3 control-label">二手车选择：</label>
                    <div class="col-sm-8">
                        <!--<input name="jumpIdGoods" class="form-control" type="text">-->
                        <select name="resId" class="form-control m-b"  >
                            <option value="">请选择</option>
                            <option th:each="dict : ${usedList}"
                                    th:text="${dict.name}"
                                    th:field="*{resId}"
                                    th:value="${dict.id}"></option>
                        </select>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <script type="text/javascript">
        var prefix = ctx + "system/banner/info";
        $("#form-banner-edit").validate({
            focusCleanup: true,
            rules:{
                sort:{
                    digits:true
                }
            }
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-banner-edit').serialize());
            }
        }

        $("#type").on("change",function(){
            if ($(this).val()==1){
                $("#banner_car").hide();
                $("#banner_activity").hide();
                $("#banner_goods").hide();
                $("#banner_used").hide();
            }
            if ($(this).val()==0){
                $("#banner_car").show();
                $("#banner_activity").hide();
                $("#banner_goods").hide();
                $("#banner_used").hide();
            }
            if ($(this).val()==2){
                $("#banner_car").hide();
                $("#banner_activity").show();
                $("#banner_goods").hide();
                $("#banner_used").hide();
            }
            if ($(this).val()==3){
                $("#banner_car").hide();
                $("#banner_activity").hide();
                $("#banner_goods").show();
                $("#banner_used").hide();
            }
            if ($(this).val()==4){
                $("#banner_car").hide();
                $("#banner_activity").hide();
                $("#banner_goods").hide();
                $("#banner_used").show();
            }
        });

        layui.use('upload', function() {
            var $ = layui.jquery
                , upload = layui.upload;

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#test1'
                , url: ctx+'/common/upload' //改成您自己的上传接口
                , done: function (res) {
                    //如果上传失败
                    if (res.code > 0) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    $("#img_header ").html("<img src='" + res.url + "' style='width:80px;height:80px;'>");
                    $("#headUrl").val(res.url);

                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText1');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
        })
        layui.use('upload', function() {
            var $ = layui.jquery
                , upload = layui.upload;

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#test2'
                , url: ctx+'/common/upload' //改成您自己的上传接口
                , done: function (res) {
                    //如果上传失败
                    if (res.code > 0) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    $("#img_backgroundUrl").html("<img src='" + res.url + "' style='width:80px;height:80px;'>");
                    $("#backgroundUrl").val(res.url);

                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText2');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
        })

    </script>
</body>
</html>